<?php

namespace zhtfrontend\models\datas;

use common\models\datas\Customer;
use Yii;

/**
 * This is the model class for table "{{%praise}}".
 *
 * @property integer $id
 * @property integer $customer_id
 * @property integer $mechanic_id
 * @property integer $lesson_id
 * @property integer $classmanage_id
 * @property integer $goods_id
 * @property string $course_name
 * @property integer $like_teacher
 * @property integer $like_course
 * @property integer $service_experience
 * @property string $content
 * @property integer $created_at
 * @property integer $total
 */
class Praise extends \zhtfrontend\components\bases\BaseModel
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%praise}}';
    }
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['customer_id', 'mechanic_id', 'lesson_id', 'classmanage_id', 'goods_id', 'like_teacher', 'like_course', 'service_experience', 'created_at', 'total','teacher_id','lesson'], 'integer'],
            [['content'], 'string'],
            [['course_name'], 'string', 'max' => 200],
            [['lesson_id','like_teacher','like_course','service_experience'],'required']
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('zhtfrontend', '自增id'),
            'customer_id' => Yii::t('zhtfrontend', '会员id'),
            'mechanic_id' => Yii::t('zhtfrontend', '机构id'),
            'lesson_id' => Yii::t('zhtfrontend', '课次id'),
            'classmanage_id' => Yii::t('zhtfrontend', '班级id'),
            'goods_id' => Yii::t('zhtfrontend', '商品id'),
            'course_name' => Yii::t('zhtfrontend', '课程名称'),
            'like_teacher' => Yii::t('zhtfrontend', '对老师的喜欢'),
            'like_course' => Yii::t('zhtfrontend', '对课程的喜欢'),
            'service_experience' => Yii::t('zhtfrontend', '服务体验度'),
            'content' => Yii::t('zhtfrontend', '表扬内容'),
            'created_at' => Yii::t('zhtfrontend', '创建时间'),
            'total' => Yii::t('zhtfrontend', '总分数'),
            'teacher_id' => Yii::t('zhtfrontend', '老师id'),
            'lesson' => Yii::t('zhtfrontend', '课次')
        ];
    }

    public function fields()
    {
        $fields = parent::fields();
        $fields['created_at'] = function () {
            return \Yii::$app->formatter->asDatetime($this->created_at);
        };
        return $fields;
    }
    public function extraFields(){
        return [
            'customer_name' => function(){
                return isset($this->customer)?$this->customer->name:'';
            },
            'mechanic_name' =>function(){
                return isset($this->mechanic)?$this->mechanic->name:'';
            },
            'teacher_name'=>function(){
                return isset($this->goodsattr)?$this->goodsattr->value:'';
            }
        ];
    }

    public function getCustomer(){
        return $this->hasOne(Customer::className(),['id'=>'customer_id']);
    }
    public function getMechanic(){
        return $this->hasOne(Mechanic::className(),['id'=>'mechanic_id']);
    }
    public function getClassLesson(){
        return $this->hasOne(ClassLesson::className(),['lesson_id'=>'lesson_id']);
    }
    public function getGoods(){
        return $this->hasOne(Goods::className(),['id'=>'goods_id']);
    }
    public function getGoodsattr(){
        return $this->hasOne(GoodsAttr::className(),['goods_id'=>'goods_id'])->where(['obj_type'=>'teacher']);
    }
    public function getTeacher(){
        return $this->hasOne(Teacher::className(),['id'=>'teacher_id']);
    }

}
